//2009/08/26 14:26:31
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class LuckyTicketSubstring
{
public:
    int maxLength(string s)
    {
        int ret = 0;
        for (int i=2; i<=s.size(); i+=2)
            for (int j=0; j+i<=s.size(); j++)
            {
                string temp = s.substr(j,i);
                if (checkLucky(temp))
                {
                    cout << "temp: " << temp << endl;
                    ret = max(ret, i);
                }
            }
        return ret;
    }
    bool checkLucky(string s)
    {
        int sum1 = 0;
		int sum2 = 0;
        if (s.size() % 2 != 0 ) return false;
        for (int i=0; i<s.size()/2; i++) sum1 += s[i] - '0';
        for (int i=s.size()/2; i<s.size(); i++) sum2 += s[i] - '0';
        if (sum1 == sum2) return true;
        return false;
    }
};
